package com.ruoyi.web.controller.construction;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.construction.CaseInfo;
import com.ruoyi.system.domain.construction.ConstructionInfo;
import com.ruoyi.system.domain.construction.FunctionalZone;
import com.ruoyi.system.domain.construction.ProjectInstruction;
import com.ruoyi.system.domain.zhuangxiumain.shopMain.BrandInfo;
import com.ruoyi.system.service.construction.CaseConstructionService;
import com.ruoyi.system.service.construction.ConstructionInfoService;
import com.ruoyi.system.service.vantservice.teamservice.ApiCaseInfoService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.nio.file.Path;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/caseinfo/info")
public class CaseInfoController extends BaseController {

    @Autowired(required = false)
    private ConstructionInfoService constructionInfoService;

    @Autowired(required = false)
    private TokenService tokenService;

    @Autowired
    private CaseConstructionService caseConstructionService;



    /**
     * 获取施工队信息列表
     */
    @PreAuthorize("@ss.hasPermi('caseinfo:info:list')")
    @RequestMapping(value = "/shigong/list",method = RequestMethod.GET)
    public TableDataInfo list(ConstructionInfo constructionInfo)
    {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        Long userId = loginUser.getUser().getUserId();
        constructionInfo.setCustomerId(userId);
        List<ConstructionInfo> list = caseConstructionService.OneConstructionInfoList(constructionInfo);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('caseinfo:info:query')")
    @GetMapping(value = "/queryInfo/{constructionId}")
    public AjaxResult getInfo(@PathVariable("constructionId") Long constructionId)
    {
        return AjaxResult.success(caseConstructionService.OnecaseInfoById(constructionId));
    }





    @PreAuthorize("@ss.hasPermi('caseinfo:info:caseConstInfoListTwo')")
    @GetMapping(value = "/caseConstInfoListTwo}")
    public TableDataInfo caseConstInfoListTwo(ConstructionInfo info){
        startPage();
        List<ConstructionInfo> constructionInfos = constructionInfoService.caseConstInfoListTwo(info);
        return getDataTable(constructionInfos);
    }





    @PreAuthorize("@ss.hasPermi('caseinfo:info:getCaseId')")
    @RequestMapping(value = "/getCaseId",method = RequestMethod.GET)
    public TableDataInfo getCaseId(CaseInfo caseInfo){
        // 开启分页
        startPage();
        List<CaseInfo> infoList = caseConstructionService.getCasefindAll(caseInfo);
        return getDataTable(infoList);
    }


    /**
     * 导出施工案例列表
     */
    @PreAuthorize("@ss.hasPermi('caseinfo:info:caseexport')")
    @Log(title = "施工案例", businessType = BusinessType.EXPORT)
    @GetMapping("/case/export")
    public AjaxResult export(CaseInfo caseInfo)
    {
        List<CaseInfo> list = caseConstructionService.getCasefindAll(caseInfo);
        ExcelUtil<CaseInfo> util = new ExcelUtil<CaseInfo>(CaseInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 获取施工案例详细信息
     */
    @PreAuthorize("@ss.hasPermi('caseinfo:info:casequery')")
    @GetMapping(value = "/case/{caseId}")
    public AjaxResult getInfo(@PathVariable("caseId") Integer caseId)
    {
        return AjaxResult.success(caseConstructionService.selectCaseInfoById(caseId));
    }

    /**
     * 新增施工案例
     */
    @PreAuthorize("@ss.hasPermi('caseinfo:info:caseadd')")
    @Log(title = "施工案例", businessType = BusinessType.INSERT)
    @PostMapping(value = "/case/add")
    public AjaxResult add(@RequestBody CaseInfo caseInfo)
    {
        Long numconstructionId = caseInfo.getNumconstructionId();
        caseInfo.setConstructionId(numconstructionId);
        caseInfo.setModifiedTime(new Date());
        caseInfo.setConStatus("0");
        return toAjax(caseConstructionService.insertCaseInfo(caseInfo));
    }

    /**
     * 修改施工案例
     */
    @PreAuthorize("@ss.hasPermi('caseinfo:info:caseedit')")
    @Log(title = "施工案例", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/case/edit")
    public AjaxResult edit(@RequestBody CaseInfo caseInfo)
    {
        return toAjax(caseConstructionService.updateCaseInfo(caseInfo));
    }

    /**
     * 删除施工案例 @DeleteMapping("/case/reomve/{caseId}")
     */
    @PreAuthorize("@ss.hasPermi('caseinfo:info:caseremove')")
    @Log(title = "施工案例", businessType = BusinessType.DELETE)
    @RequestMapping(value = "/case/reomve/{caseId}",method = RequestMethod.DELETE)
    public AjaxResult remove(@PathVariable Integer[] caseId)
    {
        return toAjax(caseConstructionService.deleteCaseInfoByIds(caseId));
    }




    //    以上是施工案例和施工对的

    //   <!--TODO 这是 是 施工案例 功能区的 -->


    /**
     * 查询施工案例功能区列表
     */
    @PreAuthorize("@ss.hasPermi('caseinfo:info:zonelist')")
    @GetMapping("/zonelist")
    public TableDataInfo zonelist(FunctionalZone functionalZone)
    {
        startPage();
        List<FunctionalZone> list = caseConstructionService.selectFunctionalZoneList(functionalZone);
        return getDataTable(list);
    }


    @PreAuthorize("@ss.hasPermi('caseinfo:info:functionalZoneZi')")
    @GetMapping("/functionalZoneZi/{caseId}")
    public List<FunctionalZone> functionalZoneZi(@PathVariable("caseId") Integer caseId){
//        startPage();
//        List<ProductCategory> list = productCategoryService.supertfindAllListTwoZi(parentId);
        return caseConstructionService.functionalZoneZi(caseId);
    }

    /**
     * 导出施工案例功能区列表
     */
    @PreAuthorize("@ss.hasPermi('caseinfo:info:zoneexport')")
    @Log(title = "施工案例功能区", businessType = BusinessType.EXPORT)
    @GetMapping("/zoneexport")
    public AjaxResult zoneexport(FunctionalZone functionalZone)
    {
        List<FunctionalZone> list = caseConstructionService.selectFunctionalZoneList(functionalZone);
        ExcelUtil<FunctionalZone> util = new ExcelUtil<FunctionalZone>(FunctionalZone.class);
        return util.exportExcel(list, "zone");
    }

    /**
     * 获取施工案例功能区详细信息
     */
    @PreAuthorize("@ss.hasPermi('caseinfo:info:zonequery')")
    @GetMapping(value = "/zone/{functionalId}")
    public AjaxResult getzoneInfo(@PathVariable("functionalId") Integer functionalId)
    {
        return AjaxResult.success(caseConstructionService.selectFunctionalZoneById(functionalId));
    }

    /**
     * 新增施工案例功能区
     */
    @PreAuthorize("@ss.hasPermi('caseinfo:info:zoneadd')")
    @Log(title = "施工案例功能区", businessType = BusinessType.INSERT)
    @PostMapping(value = "/zoneadd")
    public AjaxResult zoneadd(@RequestBody FunctionalZone functionalZone)
    {
        Integer numcaseId = functionalZone.getNumcaseId();
        functionalZone.setCaseId(numcaseId);
        return toAjax(caseConstructionService.insertFunctionalZone(functionalZone));
    }

    /**
     * 修改施工案例功能区
     */
    @PreAuthorize("@ss.hasPermi('caseinfo:info:zoneedit')")
    @Log(title = "施工案例功能区", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/zoneedit")
    public AjaxResult zoneedit(@RequestBody FunctionalZone functionalZone)
    {
        return toAjax(caseConstructionService.updateFunctionalZone(functionalZone));
    }

    /**
     * 删除施工案例功能区
     */
    @PreAuthorize("@ss.hasPermi('caseinfo:info:zoneremove')")
    @Log(title = "施工案例功能区", businessType = BusinessType.DELETE)
    @DeleteMapping("/zoneremove/{functionalId}")
    public AjaxResult zoneremove(@PathVariable Integer[] functionalId)
    {
        return toAjax(caseConstructionService.deleteFunctionalZoneByIds(functionalId));
    }



//    TODO 施工案例 说明表

//    @GetMapping(value = "/prolist/{caseId}")
    @PreAuthorize("@ss.hasPermi('caseinfo:info:prolist')")
    @RequestMapping(value = "/prolist/{caseId}",method = RequestMethod.GET)
    public List<ProjectInstruction> prolist(@PathVariable("caseId") Integer caseId){
        return caseConstructionService.selectProjectInstructionList(caseId);
    }
//    public TableDataInfo prolist(ProjectInstruction projectInstruction,Integer caseId)
//    {
//        startPage();
//        List<ProjectInstruction> list = caseConstructionService.selectProjectInstructionList(projectInstruction,caseId);
//        return getDataTable(list);
//    }

    /**
     * 导出施工案例说明列表
     */
//    @PreAuthorize("@ss.hasPermi('caseinfo:info:proexport')")
//    @Log(title = "施工案例说明", businessType = BusinessType.EXPORT)
//    @GetMapping("/pro/proexport")
//    public AjaxResult export(ProjectInstruction projectInstruction)
//    {
//        List<ProjectInstruction> list = caseConstructionService.selectProjectInstructionList(projectInstruction);
//        ExcelUtil<ProjectInstruction> util = new ExcelUtil<ProjectInstruction>(ProjectInstruction.class);
//        return util.exportExcel(list, "instruction");
//    }

    /**
     * 获取施工案例说明详细信息
     */
    @PreAuthorize("@ss.hasPermi('caseinfo:info:proquery')")
    @GetMapping(value = "/pro/{projectId}")
    public AjaxResult getproInfo(@PathVariable("projectId") Integer projectId)
    {
        return AjaxResult.success(caseConstructionService.selectProjectInstructionById(projectId));
    }

    /**
     * 新增施工案例说明
     */
    @PreAuthorize("@ss.hasPermi('caseinfo:info:proadd')")
    @Log(title = "施工案例说明", businessType = BusinessType.INSERT)
    @PostMapping(value = "/proadd")
    public AjaxResult proadd(@RequestBody ProjectInstruction projectInstruction)
    {
        Integer numcaseId = projectInstruction.getNumcaseId();
        System.err.println("**************************"+numcaseId);
        projectInstruction.setCaseId(numcaseId);
        return toAjax(caseConstructionService.insertProjectInstruction(projectInstruction));
    }

    /**
     * 修改施工案例说明
     */
    @PreAuthorize("@ss.hasPermi('caseinfo:info:proedit')")
    @Log(title = "施工案例说明", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/proedit")
    public AjaxResult proedit(@RequestBody ProjectInstruction projectInstruction)
    {
        return toAjax(caseConstructionService.updateProjectInstruction(projectInstruction));
    }

    /**
     * 删除施工案例说明
     */
    @PreAuthorize("@ss.hasPermi('caseinfo:info:proremove')")
    @Log(title = "施工案例说明", businessType = BusinessType.DELETE)
    @DeleteMapping("/proremove/{projectId}")
    public AjaxResult proremove(@PathVariable Integer[] projectId)
    {
        return toAjax(caseConstructionService.deleteProjectInstructionByIds(projectId));
    }















}
